import { ImageResponse } from 'next/og'; import { t } from '@/i18n'; import { safe } from '@/lib/api'; import { apiCompare } from '@/lib/api-compare'; import { displayValue } from '@/lib/format'; import { OG_INK2, OG_INK3, OG_RULE, OG_SIZE_H, OG_SIZE_W, OgFrame, OgWordmark } from '../../og-shared'; export const alt = 'Country ranking on CountryAtlas'; export const size = { width: OG_SIZE_W, height: OG_SIZE_H }; export const contentType = 'image/png'; export const revalidate = 3600; /** Social image for /rankings/[indicator]: title + the top 3 (flag, name, value). */ export default async function RankingOgImage({ params }: { params: Promise<{ indicator: string }> }) { const { indicator } = await params; const data = await safe(apiCompare.ranking(indicator, { limit: 3, sparkline: false })); const name = data?.indicator.short_name ?? data?.indicator.name ?? indicator.replace(/-/g, ' '); const year = data?.year_used ?? ''; return new ImageResponse( (
{t('rankings.title')}
28 ? 52 : 64, fontWeight: 600, letterSpacing: -1.5, lineHeight: 1.05, marginTop: 8, display: 'flex' }}>{t('ranking.heading', { name })}
{year ?
{`${String(year)}${data ? ` ยท ${data.n} countries` : ''}`}
: null}
{(data?.rows ?? []).slice(0, 3).map((r) => (
{String(r.rank)}
{r.country.flag ?? ''}
{r.country.name ?? r.country.id}
{displayValue(r.value, data!.indicator, r.formatted)}
))}
{t('og.site')}
), { ...size }, ); }